#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		x ^= x << 13;
		x ^= x >> 7;
		x ^= x << 17;
		return x; 
	}
	size_t operator () (uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
		return splitmix64(x + FIXED_RANDOM);
	}
};

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int t = 0;
    for(auto ch : s)
    {
        t += (ch - '0');
    }
    int ans = INT_MAX;
    int res = 0;
    if(t >= (n + 1) / 2){
        res = 0;
        ans = n / 2 - 1;
    }
    int a = 0;
    for(int i = 1; i <= n; i++)
    {
        if(s[i - 1] == '1') a++;
        if(i - a >= (i + 1) / 2 && t - a >= (n - i + 1) / 2)
        {
            if(abs(n / 2 - i) < ans)
                res = i;
        }
    }
    cout << res << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}